﻿
    
/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A
 * copy of the license can be found at http://go.microsoft.com/fwlink/?LinkID=131993. If
 * you cannot locate the Microsoft Public License, please send an email to
 * mixon@microsoft.com. By using this source code in any fashion, you are agreeing to
 * be bound by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/
    

if (!window.Silverlight) {
    window.Silverlight = {};
}

Silverlight.onSilverlightInstalled = function() { window.location.reload(false); };

Silverlight.isInstalled = function(version) {
    var isVersionSupported = false;
    var container = null;

    try {
        var control = null;

        try {
            control = new ActiveXObject('AgControl.AgControl');
            if (version == null) {
                isVersionSupported = true;
            }
            else if (control.IsVersionSupported(version)) {
                isVersionSupported = true;
            }
            control = null;
        }
        catch (e) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (version === null) {
                    isVersionSupported = true;
                }
                else {
                    var actualVer = plugin.description;
                    if (actualVer === "1.0.30226.2")
                        actualVer = "2.0.30226.2";
                    var actualVerArray = actualVer.split(".");
                    while (actualVerArray.length > 3) {
                        actualVerArray.pop();
                    }
                    while (actualVerArray.length < 4) {
                        actualVerArray.push(0);
                    }
                    var reqVerArray = version.split(".");
                    while (reqVerArray.length > 4) {
                        reqVerArray.pop();
                    }

                    var requiredVersionPart;
                    var actualVersionPart
                    var index = 0;


                    do {
                        requiredVersionPart = parseInt(reqVerArray[index]);
                        actualVersionPart = parseInt(actualVerArray[index]);
                        index++;
                    }
                    while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);

                    if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
                        isVersionSupported = true;
                    }
                }
            }
        }
    }
    catch (e) {
        isVersionSupported = false;
    }
    if (container) {
        document.body.removeChild(container);
    }

    return isVersionSupported;
}

Silverlight.WaitForInstallCompletion = function() {
    if (Silverlight.onSilverlightInstalled) {
        try {
            navigator.plugins.refresh();
        }
        catch (e) {
        }
        if (Silverlight.isInstalled(null)) {
            Silverlight.onSilverlightInstalled();
        }
        else {
            setTimeout(Silverlight.WaitForInstallCompletion, 3000);
        }
    }
}


Silverlight.__startup = function() {
    var installed = Silverlight.isInstalled(null);

    if (!installed) {
        var elem;
        
        elem = document.getElementById("getsilverlight");
        elem.style.display = "block";
        elem = document.getElementById("visualization");
        elem.style.display = "none";

        Silverlight.WaitForInstallCompletion();

    }

    if (window.removeEventListener) {
        window.removeEventListener('load', Silverlight.__startup, false);
    }
    else {
        window.detachEvent('onload', Silverlight.__startup);
    }
}

if (window.addEventListener) {
    window.addEventListener('load', Silverlight.__startup, false);
}
else {
    window.attachEvent('onload', Silverlight.__startup);
}